package com.woniuxy.classdeans.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.classdeans.service.AuditService;
import com.woniuxy.commons.entity.Vedio;
import com.woniuxy.commons.entity.wyh.VideoTeacherDto;
import com.woniuxy.commons.entity.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author weizihan
 * @Date 2020/7/27 2020/7/27
 * @Description 视屏审核+文章审核
 * @Since version-1.0
 */
@RestController
@RequestMapping("/audit")
public class AuditController {

    @Autowired
    private AuditService auditService;

    //展示没审核的视频
    @RequestMapping("/selectVideoAll")
    public ResponseResult<PageInfo<Vedio>> selectVideoAll(@RequestParam(value = "pn",defaultValue = "1")Integer pn){

        PageHelper.startPage(pn,5);

        List<Vedio> vedios = auditService.selectVedios();

        PageInfo<Vedio> page = new PageInfo<Vedio>(vedios,5);

        return  new ResponseResult<PageInfo<Vedio>>().setCode(200).setMessage("视屏全部查询出").setData(page);
    }

    //通过vid获取相关的Vedio属性
    @RequestMapping("/findByVid/{vid}")
    public ResponseResult<Vedio> findByVid(@PathVariable("vid") Integer vid){
       // System.out.println(vid);
        Vedio vedio = auditService.findByVid(vid);
        System.out.println(vedio);
        return new ResponseResult<Vedio>().setCode(200).setMessage("视频获取成功").setData(vedio);
    }

    //审核视频
    @RequestMapping("/video/{vid}/{examine}")
    public ResponseResult auditVideo(@PathVariable("vid") Integer vid,@PathVariable("examine") Integer examine){
        System.out.println("vid="+vid+",examine="+examine);
        Integer result = auditService.updateVideoAudit(new Vedio().setVid(vid).setExamine(examine));
        if (result != -1) {
            return new ResponseResult().setCode(200).setMessage("审核完成").setData("ok");
        }else {
            return new ResponseResult().setCode(400).setMessage("审核失败").setData("失败");
        }
    }
}
